package xiaof.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import xiaof.dao.UserDao;
import xiaof.service.UserService;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.annotation.Resource;

/*<bean id="userService" class="xiaof.service.impl.UserServiceImpl">

</bean>*/
//@Component("userService")
@Service("userService")
@Scope("singleton")
public class UserServiceImpl implements UserService {
    @Value("${jdbc.driver}")

    private String driver;
   /* @Value("${jdbc.url}")
    private String url;*/
//    <property name="userDao" ref="userDao" ></property>
    @Autowired//按照数据类型从Spring容器中匹配
    @Qualifier("userDao")//按照id从容器中进行匹配，需要结合@Autowired一起用
    //@Resource(name = "userDao")//相当于autowired和@Qualifier结合使用
    private UserDao userDao;

  /*  public void setUserDao(UserDao userDao) {
        this.userDao = userDao;
    }*/
    @PostConstruct
    public void init(){
        System.out.println("初始化方法");
    }
    @Override
    public void save() {
        //System.out.println(url);
        System.out.println(driver);
        userDao.save();

    }
    @PreDestroy
    public void destory(){
        System.out.println("销毁方法");
    }
}

